package bancosys.tec.rtm.diagnostician;

import java.io.OutputStream;
import java.util.List;

import bancosys.tec.rtm.diagnostician.report.DiagnosticianReportGenerator;

/**
 * Implementação generica para DiagnosticianCase.
 * 
 * @author Evaristo
 * @version $Id:$ <b>Created on: </b> 05/03/2007
 */
public abstract class GenericDiagnosticianCase implements DiagnosticianCase {

    /**
     * Implementação default para o método que executa os diagnosticadores do sistema.
     * 
     * @param reportGenerator DiagnosticianReportGenerator
     * @param outputStream OutputStream
     * @throws Exception - Qualquer erro decorrente da execução dos diagnosticadores
     */
    public void executeDiagnostician(DiagnosticianReportGenerator reportGenerator, OutputStream outputStream) throws Exception {
        this.genericExecuteDiagnostician(reportGenerator, outputStream, this.getDiagnosticiansListOfSystem());
    }

    /**
     * Implementação default para o método que executa os diagnosticadores do sistema em modo debug.
     * 
     * @param reportGenerator DiagnosticianReportGenerator
     * @param outputStream OutputStream
     * @throws Exception - Qualquer erro decorrente da execução dos diagnosticadores
     */
    public void executeDiagnosticianInDebugMode(DiagnosticianReportGenerator reportGenerator, OutputStream outputStream) throws Exception {
        this.genericExecuteDiagnostician(reportGenerator, outputStream, this.getDiagnosticiansListOfSystemInDebugMode());
    }

    /**
     * Método privado para encapsular a logica generica de execução do diagnosticador.
     * 
     * @param reportGenerator regrador de report
     * @param outputStream stream de saida
     * @param diagnosticiansList lista de diagnosticadores
     * @throws Exception - Qualquer erro decorrente da execução dos diagnosticadores
     */
    private void genericExecuteDiagnostician(DiagnosticianReportGenerator reportGenerator, OutputStream outputStream,
            List<? extends Diagnostician> diagnosticiansList) throws Exception {
        DiagnosticianController controller = new DiagnosticianController(reportGenerator);
        controller.addDiagnosticianList(diagnosticiansList);
        controller.generateReportOfDiagnosticians(outputStream);
        outputStream.flush();
    }

    /**
     * {@inheritDoc}
     */
    public List<? extends Diagnostician> getDiagnosticiansListOfSystem() throws Exception {
        return this.getDiagnosticiansListOfSystemInDebugMode();
    }

}